import { createRouter, createWebHistory } from 'vue-router'
import Login from '../pages/Login.vue'
import Page1 from '../pages/Page1.vue'
import AdminLayout from '../layouts/AdminLayout.vue'
import { isLogin } from '../utils//tools'

const routes = [
  { path: '/login', component: Login },
  {
    path: '/',
    component: AdminLayout,
    beforeEnter: (to, from, next) => {
      isLogin() ? next() : next('/login')
    },
    children: [
      { path: '', redirect: '/page1' },
      { path: 'page1', component: Page1 },
      {
        path: 'other',
        component: {
          template: '<div><h2>其他页面内容</h2></div>'
        }
      }
    ]
  }
]

export default createRouter({
  history: createWebHistory(),
  routes
})
